<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="销售日期">
        <el-date-picker
          v-model="daterangeSellDate"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="商品线上id" prop="goodsOnlineid" label-width="auto">
        <el-input
          v-model="queryParams.goodsOnlineid"
          placeholder="请输入商品线上id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品线上id1" prop="goods1Onlineid" label-width="auto">
        <el-input
          v-model="queryParams.goods1Onlineid"
          placeholder="请输入商品线上id1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品线上id2" prop="goods2Onlineid" label-width="auto">
        <el-input
          v-model="queryParams.goods2Onlineid"
          placeholder="请输入商品线上id2"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['item:goodssellcontrast:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['item:goodssellcontrast:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['item:goodssellcontrast:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['item:goodssellcontrast:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="goodssellcontrastList" @selection-change="handleSelectionChange" :summary-method="getSummaries">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="销售日期" align="center" prop="sellDate" width="80">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sellDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="商品1" align="center" >
        <el-table-column label="id" align="center" prop="sdNum" >
          <el-table-column label="总流量" align="center" prop="goodssellNum" width="50"/>
          <el-table-column label="sd单量" align="center" prop="sdNum" width="50"/>
          <el-table-column label="浮动" align="center" prop="sdNum1" width="70">
            <template slot-scope="scope" >
              <span  v-if="scope.row.sdNum != null && scope.row.sdNum1 != null">{{((scope.row.sdNum-scope.row.sdNum1)*100/scope.row.sdNum1  | rounding)+'%'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="整体转化" align="center" :formatter="rounding" width="60">
            <template slot-scope="scope" >
              <span  v-if="scope.row.sdNum != null && scope.row.goodssellNum != null">{{(scope.row.sdNum*100 /scope.row.goodssellNum  | rounding)+'%'}}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="图片" align="center" prop="sdNum">
          <el-table-column label="手淘搜索" align="center" prop="searchsellNum" width="50"/>
          <el-table-column label="浮动" align="center" width="70">
            <template slot-scope="scope" >
              <span  v-if="scope.row.searchsellNum != null && scope.row.searchsellNum1 != null">{{(scope.row.searchsellNum*100/scope.row.searchsellNum1 | rounding)+'%'}}</span>
            </template>
          </el-table-column>
            <el-table-column label="搜索成交量" align="center" prop="searchRates" width="50"/>
            <el-table-column label="搜索转化率" align="center" :formatter="rounding" width="60">
              <template slot-scope="scope" >
                <span  v-if="scope.row.searchsellNum != null && scope.row.searchRates != null">{{(scope.row.searchRates*100/scope.row.searchsellNum | rounding)+'%'}}</span>
              </template>
            </el-table-column>
          </el-table-column>
        <el-table-column label="" align="center" prop="sdNum">
          <el-table-column label="真实成交" align="center" prop="realPay" width="50"/>
          <el-table-column label="真实转化" align="center" prop="" width="50"/>
          <el-table-column label="付费流量" align="center" prop="payFlow" width="50"/>
        </el-table-column>
        </el-table-column>

      <el-table-column label="商品2" align="center" >
        <el-table-column label="id" align="center" prop="sd1Num" >
          <el-table-column label="总流量" align="center" prop="goodssell1Num" width="50"/>
          <el-table-column label="sd单量" align="center" prop="sd1Num" width="50" />
          <el-table-column label="浮动" align="center" width="70">
            <template slot-scope="scope" >
              <span  v-if="scope.row.sd1Num != null && scope.row.sd1Num1 != null">{{((scope.row.sd1Num-scope.row.sd1Num1)*100/scope.row.sd1Num1  | rounding)+'%'}}</span>
            </template>
        </el-table-column>
          <el-table-column label="整体转化" align="center" :formatter="rounding" width="60">
            <template slot-scope="scope" >
              <span  v-if="scope.row.goodssell1Num != null && scope.row.sd1Num != null">{{(scope.row.sd1Num*100/scope.row.goodssell1Num  | rounding)+'%'}}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="图片" align="center" prop="sdNum">
          <el-table-column label="手淘搜索" align="center" prop="searchsell1Num" width="50"/>
          <el-table-column label="浮动" align="center"  width="70">
            <template slot-scope="scope" >
              <span  v-if="scope.row.searchsell1Num != null && scope.row.searchsell1Num1 != null">{{(scope.row.searchsell1Num*100/scope.row.searchsell1Num1 | rounding)+'%'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="搜索成交量" align="center" prop="search1Rates" width="50">
          </el-table-column>
          <el-table-column label="搜索转化率" align="center" :formatter="rounding" width="60">
            <template slot-scope="scope" >
              <span  v-if="scope.row.searchsell1Num != null && scope.row.search1Rates != null">{{(scope.row.search1Rates*100/scope.row.searchsell1Num | rounding)+'%'}}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="" align="center" prop="sdNum">
          <el-table-column label="真实成交" align="center" prop="real1Pay" width="50"/>
          <el-table-column label="真实转化" align="center" prop="" width="50"/>
          <el-table-column label="付费流量" align="center" prop="pay1Flow" width="50"/>
        </el-table-column>
      </el-table-column>

      <el-table-column label="商品3" align="center" >
        <el-table-column label="id" align="center" prop="sd2Num" >
          <el-table-column label="总流量" align="center" prop="goodssell2Num" width="50"/>
          <el-table-column label="sd单量" align="center" prop="sd2Num" width="50"/>
          <el-table-column label="浮动" align="center" width="70">
            <template slot-scope="scope" >
              <span  v-if="scope.row.sd2Num != null && scope.row.sd2Num1 != null">{{((scope.row.sd2Num-scope.row.sd2Num1)*100/scope.row.sd2Num1  | rounding)+'%'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="整体转化" align="center" :formatter="rounding" width="60">
            <template slot-scope="scope" >
              <span  v-if="scope.row.goodssell2Num != null && scope.row.sd2Num != null">{{(scope.row.sd2Num*100/scope.row.goodssell2Num  | rounding)+'%'}}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="图片" align="center" >
          <el-table-column label="手淘搜索" align="center" prop="searchsell2Num" width="50"/>
          <el-table-column label="浮动" align="center" width="70">
            <template slot-scope="scope" >
              <span  v-if="scope.row.searchsell2Num != null && scope.row.searchsell2Num1 != null">{{(scope.row.searchsell2Num*100/scope.row.searchsell2Num1 | rounding)+'%'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="搜索成交量" align="center" prop="search2Rates" width="50"/>
          <el-table-column label="搜索转化率" align="center" :formatter="rounding" width="60">
            <template slot-scope="scope" >
              <span  v-if="scope.row.searchsell2Num != null && scope.row.search2Rates != null">{{(scope.row.search2Rates*100/scope.row.searchsell2Num | rounding)+'%'}}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="" align="center" >
          <el-table-column label="真实成交" align="center" prop="real2Pay" width="50"/>
          <el-table-column label="真实转化" align="center" prop="" width="50"/>
          <el-table-column label="付费流量" align="center" prop="pay2Flow" width="50"/>
        </el-table-column>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import { listGoodssellcontrast } from "@/api/item/goodssellcontrast";

export default {
  name: "Goodssellcontrast",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 在线商品销售表格数据
      goodssellcontrastList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 备注时间范围
      daterangeSellDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sellDate: null,
        goodsOnlineid: null,
        goodssellNum: null,
        goodsRates: null,
        searchsellNum: null,
        searchRates: null,
        sdNum: null,
        sdNum1: null,
        feedCost: null,
        sales: null,
        profit: null,
        searchsell1Num: null,
        searchsell2Num: null,
        search1Rates: null,
        search2Rates: null,
        sd1Num: null,
        sd2Num: null,
        goods1Onlineid: null,
        goods2Onlineid: null,
        goodssell1Num: null,
        goodssell2Num: null,
        searchsell1Num1: null,
        searchsellNum1: null,
        searchsell2Num1: null,
        sd1Num1: null,
        sd2Num1: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询在线商品销售列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeSellDate && '' != this.daterangeSellDate) {
        this.queryParams.params["beginSellDate"] = this.daterangeSellDate[0];
        this.queryParams.params["endSellDate"] = this.daterangeSellDate[1];
      }
      listGoodssellcontrast(this.queryParams).then(response => {
        this.goodssellcontrastList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        goodsId: null,
        sellDate: null,
        goodsOnlineid: null,
        goodssellNum: null,
        goodsRates: null,
        searchsellNum: null,
        searchRates: null,
        sdNum: null,
        feedCost: null,
        sales: null,
        profit: null,
        remark: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeSellDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.goodsId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('item/goodssellcontrast/export', {
        ...this.queryParams
      }, `goodssellcontrast_${new Date().getTime()}.xlsx`)
    },

    rounding(row,column) {
      return parseFloat(row[column.property]).toFixed(5)
    },


    filters: {
      rounding (value) {
        return value.toFixed(5)
      }
    },

  }


};
</script>
